# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=pcre2
pkgver=10.43
pkgrel=0
pkgdesc="Perl-compatible regular expression library"
url="https://pcre.org/"
arch="all"
license="BSD-3-Clause"
depends_dev="
	libedit-dev
	zlib-dev
	"
makedepends="$depends_dev"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-tools
	libpcre2-16:_libpcre
	libpcre2-32:_libpcre
	"
source="https://github.com/PhilipHazel/pcre2/releases/download/pcre2-$pkgver/pcre2-$pkgver.tar.bz2"

# secfixes:
#   10.41-r0:
#     - CVE-2022-41409
#   10.40-r0:
#     - CVE-2022-1586
#     - CVE-2022-1587

build() {
	# Note: Forced -O3 is recommended (needed?) for Julia.
	./configure \
		CFLAGS="$CFLAGS -O3" \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--docdir=/usr/share/doc/$pkgname-$pkgver \
		--htmldir=/usr/share/doc/$pkgname-$pkgver/html \
		--enable-pcre2-16 \
		--enable-pcre2-32 \
		--enable-pcre2grep-libz \
		--enable-pcre2test-libedit \
		--enable-jit
	make
}

check() {
	./RunTest
	./pcre2_jit_test
}

package() {
	make DESTDIR="$pkgdir" install
}

_libpcre() {
	local bits="${subpkgname##*-}"
	pkgdesc="PCRE2 with $bits bit character support"

	amove usr/lib/libpcre2-$bits.so*
}

tools() {
	pkgdesc="Auxiliary utilities for PCRE2"

	amove usr/bin
}

sha512sums="
8ac1520c32e9e5672404aaf6104e23c9ee5c3c28ad28ff101435599d813cbb20e0491a3fd34e012b4411b3e0366a4c6dfa3f02d093acaa6ff0ab25478bb7ade9  pcre2-10.43.tar.bz2
"
